package com.ls.kdlss.ui.my;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;

import com.gm.lib.views.titlebar.AbTitleBar;
import com.ls.kdlss.R;
import com.ls.kdlss.ui.Login.RegisterActivity;
import com.ls.kdlss.ui.home.AnswerActivity;
import com.ls.kdlss.ui.home.FeedBackActivity;
import com.ls.kdlss.ui.home.ReadingActivity;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * 我的
 */

public class FindFragment extends Fragment implements View.OnClickListener {


    @Bind(R.id.rv_imgtitle)
    ImageView rvImgtitle;
    @Bind(R.id.rv_view)
    RecyclerView rvView;
    @Bind(R.id.title_bar)
    AbTitleBar titleBar;


    public static FindFragment getInstance() {
        return new FindFragment();
    }

    private View view;
    private CommonAdapter<String> commonAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.activity_find, null);
        ButterKnife.bind(this, view);
        setInfo();

        return view;
    }


    @Override
    public void onClick(View v) {
    }

    public void setInfo() {

        titleBar.setTitleText("发现");
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        rvView.setLayoutManager(manager);
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        commonAdapter = new CommonAdapter<String>(getContext(), R.layout.cell_news, list) {
            @Override
            protected void convert(ViewHolder holder, String s, int position) {
               switch (position){

                   case 0:
                       holder.getView(R.id.ll_viewswww).setOnClickListener(new View.OnClickListener() {
                           @Override
                           public void onClick(View v) {
                               AnswerActivity.launch(getContext());
                           }
                       });
                       break;
                   case 1:
                       holder.getView(R.id.ll_viewswww).setOnClickListener(new View.OnClickListener() {
                           @Override
                           public void onClick(View v) {
                               ReadingActivity.lanuch(getContext());
                           }
                       });
                       break;

                   case 2:
                       holder.getView(R.id.ll_viewswww).setOnClickListener(new View.OnClickListener() {
                           @Override
                           public void onClick(View v) {
                               FeedBackActivity.launch(getContext());
                           }
                       });
                       break;
                   case 3:
                       holder.getView(R.id.ll_viewswww).setOnClickListener(new View.OnClickListener() {
                           @Override
                           public void onClick(View v) {


                               nianjian();

                           }
                       });
                       break;
               }



            }
        };
        rvView.setAdapter(commonAdapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
    /**
     * 年检弹窗
     */
    public void nianjian() {
        final Dialog alertDialog = new Dialog(getContext());
        alertDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        Window window = alertDialog.getWindow();
        alertDialog.show();
        window.setContentView(R.layout.dialog_share);

        /*Button button = (Button) window.findViewById(R.id.button6);
        button.setVisibility(View.GONE);
        ImageView imageView4 = (ImageView) window.findViewById(R.id.imageView4);
        imageView4.setBackgroundResource(R.drawable.door_prompt);
        ImageView iv_close = (ImageView) window.findViewById(R.id.iv_close);
        iv_close.setVisibility(View.VISIBLE);
        iv_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
            }
        });*/

    }
}
